package com.ggh.jinjilive.ui.home.voice;

import androidx.databinding.ObservableField;
import androidx.lifecycle.MutableLiveData;

import com.ggh.jinjilive.mobile.ResultEntity;
import com.ggh.jinjilive.mobile.home.live.LiveCategory;
import com.ggh.jinjilive.mobile.home.voice.VoiceHot;
import com.ggh.jinjilive.remotedata.InterceptObserver;
import com.ggh.jinjilive.remotedata.systemapi.SystemApiService;
import com.ggh.jinjilive.ui.BaseViewModel;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class VoiceViewModel extends BaseViewModel {
    //娱乐 带货 红人 热门 才艺 游戏 体育
    public ObservableField<String> cate_id = new ObservableField<>("0");
    //语音房类目
    public MutableLiveData<List<LiveCategory>> listMutableLiveData = new MutableLiveData<>();
    //语音房列表语热门
    public MutableLiveData<List<VoiceHot>> mVoiceHot = new MutableLiveData<>();

    public VoiceViewModel(SystemApiService apiCallInterface) {

        super(apiCallInterface);
    }

    /**
     * 语音房类目
     */
    public void voiceCateList(){
        Map<String, Object> paramsa = new HashMap<>();
        addSubscribe(apiCallInterface.voiceCateList(paramsa).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribeWith(new InterceptObserver<ResultEntity<List<LiveCategory>>>() {
            @Override
            public void onNextData(ResultEntity resultEntity) {
                List<LiveCategory> liveCategoryList = (List<LiveCategory>) resultEntity.getData();
                listMutableLiveData.setValue(liveCategoryList);
            }

            @Override
            public void onErrorNet(Throwable t, String netMsg) {

            }

        }));
    }

    /**
     * 语音房热门
     */
    public void hotList(){
        if (isRefresh) {
            page = 1;
        }else {
            page = page + 1;
        }
        Map<String, Object> paramsa = new HashMap<>();
        paramsa.put("page",page);
        paramsa.put("limit",pageSize);
        addSubscribe(apiCallInterface.hotList(paramsa).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribeWith(new InterceptObserver<ResultEntity<List<VoiceHot>>>() {
                    @Override
                    public void onNextData(ResultEntity resultEntity) {
                        List<VoiceHot> voiceHotList = (List<VoiceHot>) resultEntity.getData();
                        mVoiceHot.setValue(voiceHotList);
                    }

                    @Override
                    public void onErrorNet(Throwable t, String netMsg) {

                    }

                }));
    }
    /**
     * 语音房列表
     */
    public void voiceList(){
        if (isRefresh) {
            page = 1;
        }else {
            page = page + 1;
        }
        Map<String, Object> paramsa = new HashMap<>();
        paramsa.put("page",page);
        paramsa.put("limit",pageSize);
        paramsa.put("cate_id",cate_id.get());
        addSubscribe(apiCallInterface.list(paramsa).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribeWith(new InterceptObserver<ResultEntity<List<VoiceHot>>>() {
                    @Override
                    public void onNextData(ResultEntity resultEntity) {
                        List<VoiceHot> voiceHotList = (List<VoiceHot>) resultEntity.getData();
                        mVoiceHot.setValue(voiceHotList);
                    }

                    @Override
                    public void onErrorNet(Throwable t, String netMsg) {

                    }

                }));
    }
}
